package com.lovo.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.system.dto.PageDto;
import com.lovo.system.dto.SupplierDto;
import com.lovo.system.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 供应商
 */

@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    ISupplierService supplierService;

    @RequestMapping("/info")
    public IPage<SupplierDto> info(@RequestBody PageDto<SupplierDto> pageDto) {
        return supplierService.cutByItem(pageDto.getCurPage(), pageDto.getPageSize()
                , pageDto.getData().getSupplierName(), pageDto.getData().getNatureOfBusiness());
    }

    @RequestMapping("/add")
    public String addSupplier(@RequestBody SupplierDto supplierDto) {
        return supplierService.addSupplier(supplierDto);
    }

    @RequestMapping("/delete")
    public String deleteSupplier(int id) {
        return supplierService.deleteSupplier(id);
    }

    @RequestMapping("/update")
    public String updateSupplier(@RequestBody SupplierDto supplierDto) {
        return supplierService.updateStudent(supplierDto);
    }

    @RequestMapping("/one")
    public SupplierDto selectSupplierById(int id) {
        return supplierService.queryOneById(id);
    }

    @RequestMapping( "/importExcel")
    public void importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        supplierService.importSupplierList(file);
    }
}
